﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace tamlytre
{
    public partial class News : System.Web.UI.Page
    {
        public static int idnews = 0;
        public static int cateid = 0;
        public static string title;
        public static string maincontent;
        public static string content;
        public static string anh;
        public static string ghichuanh;
        public static string titlenosign;
        DBTuVanDataContext db = new DBTuVanDataContext();//khai báo lớp DataContext
        public void NewsConnection()
        {
            int a;
            var count = db.TB_News.Count(n => n.idNews <= idnews);
            if (count > 3)
            {
                a = count - 3;
            }
            else
                a = count;
            var newscnt = (from n in db.TB_News
                           where n.Cate_ID == cateid
                           select n).Skip(a).Take(10);
            UC_NewsConnection1.ListNewsConnection = newscnt.ToList();
        }
        public void NewsNew()
        {
            var newsnew = (from n in db.TB_News
                           select n).Take(15);
            UC_NewsNew1.ListNewsNew = newsnew.ToList();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bool bSuc = Int32.TryParse(Request.QueryString["id"], out idnews);
                if (bSuc == true)
                {
                    using (DBTuVanDataContext db = new DBTuVanDataContext())
                    {
                        TB_New news = db.TB_News.Single(id => id.idNews == idnews);
                        news.NumViews = news.NumViews + 1;
                        db.SubmitChanges();
                        maincontent = news.MainContent;
                        content = news.Content;
                        anh = "../images/" + news.Picture;
                        ghichuanh = news.PictureNote;
                        cateid = news.Cate_ID;
                        MetaKeywords = news.Keyword + "| Tâm lý trẻ | Tư vấn tâm lý";
                        MetaDescription = news.TitleNosign + "| Tâm lý trẻ | Tư vấn tâm lý ";
                        Title = news.Title +"| Tâm lý trẻ | Tư vấn tâm lý ";
                    }
                }
                NewsConnection();
                NewsNew();
            }
        }
    }
}